/**
 * Created by fangzehua on 2017/7/8.
 */
/**
 * Created by fangzehua on 2017/7/8.
 */
/**
 * Created by fangzehua on 2017/7/4.
 */
$(function () {


    //菜单列表
    $('#specialTableEvents').bootstrapTable({
        url: "specialList",
        search: false,
        pagination: true,
        showRefresh: false,
        showToggle: false,
        showColumns: false,
        pageSize:15,
        height:600,
        iconSize: 'outline',
        toolbar: '#specialTableEventsToolbar',
        columns:[
            {
                field:'id',
                title:'ID',
                width:60
            },
            {
                field:'title',
                title:'名称',
                width:200
            },
            {
                field:'nums',
                title:'商品数量',
                width:60
            },
            {
                field:'author',
                title:'作者',
                width:60
            },
            {
                field:'type',
                title:'类型',
                width:60,
                formatter: function(value, row, index) {
                    if(row.type == '0') {
                        return "--";
                    } else {
                        return "网页";
                    }
                }
            },
            {
                field:'attribute',
                title:'属性',
                width:60,
                formatter: function(value, row, index) {
                    if(row.attribute == '0') {
                        return "--";
                    } else {
                        return "搭配";
                    }
                }
            },
            {
                field:'clicks',
                title:'点击次数',
                width:80
            },
            {
                field:'flag',
                title:'状态',
                width:60,
                formatter: function(value, row, index) {
                    if(row.flag == '0') {
                        return "<font color='#228b22'>正常</font>";
                    } else {
                        return "<font color='#dcdcdc'>下架</font>";
                    }
                }
            },
            {
                field:'starttime',
                title:'开始时间',
                width:150
            },
            {
                field:'endtime',
                title:'结束时间',
                width:150
            },
            {
                field:'addtime',
                title:'添加时间',
                width:150
            },
            {
                field:'action',
                title:'操作',
                width:200,
                formatter: function(value, row, index) {
                    return [
                        '<shiro:hasPermission name="admin:ordervip:update">'+
                        '<a class="edit ml10" href="javascript:void(0)" title="修改">'+
                        '<i class="glyphicon glyphicon-edit"></i></a></shiro:hasPermission>&nbsp;&nbsp;&nbsp;&nbsp;',
                        '<shiro:hasPermission name="admin:ordervip:plus">'+
                        '<a class="plus ml12" href="javascript:void(0)" title="参数">'+
                        '<i class="glyphicon glyphicon-plus"></i></a></shiro:hasPermission>&nbsp;&nbsp;&nbsp;&nbsp;',
                        '<shiro:hasPermission name="admin:ordervip:clear">'+
                        '<a class="delete ml12" href="javascript:void(0)" title="删除">'+
                        '<i class="glyphicon glyphicon-remove-circle"></i></a></shiro:hasPermission>'
                    ].join('');
                },    //紫色为添加图标（icon），插件：font-awesome，效果图见底部。
                events: {
                    'click .delete': function(e, value, row, index) {
                        $.confirm({
                            title: '刪除!',
                            content: '确认删除该专题吗!',
                            confirm: function(){
                                $.ajax({
                                    url: "delSpecial",
                                    data: row.id,
                                    type: "post",
                                    contentType: "application/json",
                                    dataType:"json",
                                    success: function (data) {
                                        if(data["retType"] == "0") {
                                            toastr.success("删除成功!");
                                            $("#specialTableEvents").bootstrapTable("refresh");
                                        } else {
                                            alert(data["retMsg"]);
                                        }
                                    }
                                });
                            },
                            cancel: function(){

                            }
                        });
                    },
                    'click .edit': function(e, value, row, index) {
                        window.location.href="doEditor/"+row.id;
                    },
                    'click .plus': function(e, value, row, index) {
                        window.location.href="product/"+row.id;
                    }
                }
            },
        ]
    });



});

